// 设置 rem 函数
function setRem() {
    let num = 16;


    if(false) {
        // 按高度来
        const screenHeight = 1080
        const scale = screenHeight / 16
        const htmlHeight = document.documentElement.clientHeight || document.body.clientHeight
        num = htmlHeight / scale
    }
    else {
        // 1920 默认大小16px; 1920px = 120rem ;每个元素px基础上/16
        const screenWidth = 1920
        const scale = screenWidth / 16
        const htmlWidth = document.documentElement.clientWidth || document.body.clientWidth
        num = htmlWidth / scale
    }
    // 得到html的Dom元素
    const htmlDom = document.getElementsByTagName('html')[0]
    // 设置根元素字体大小
    htmlDom.style.fontSize = `${num}px`
}
// 初始化
setRem()



// 改变窗口大小时重新设置 rem
window.addEventListener('resize', function() {
    setRem()
})